home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
PROBLEMS
/
BENCHMARK
/
BUBBLESORT
/
bubbletest
/
AnsiC_2
/
c
/
source
Wrap
C/C++ Source or Header
|
1992-06-17
|
1KB
|
72 lines
/* bubbletest source file */
/* */
/* compiled using Acorn C Release 4 */
/* */
#include <stdio.h>
#define BOOL int
#define TRUE 1
#define FALSE 0
#define length 1000
void init_array(void);
void bubblesort(void);
void print_array(void);
int array[length];
int main()
{
init_array();
print_array();
os_cli("show time1");
bubblesort();
os_cli("show time1");
print_array();
}
void init_array()
{
int count;
int pseudorandom=123456;
for (count=0;count<length;count++)
{
pseudorandom=(pseudorandom + 234567) % 567 + 345;
array[count]=pseudorandom;
}
}
void bubblesort()
{
register int temp;
register int *p;
register int *end;
BOOL sorted;
end=array+length-2;
do
{
sorted=TRUE;
p=array; temp=*p;
do
{
if (temp>*(p+1))
{
*p=*(p+1);
*(p+1)=temp; sorted=FALSE;
}
else temp=*(p+1);
}
while ((p++)!=end);
}
while (!sorted);
}
void print_array()
{
int i;
for (i=0;i<1000;i++)
{
printf("%d\n",array[i]);
}
}